package com.buka.controller;

import com.buka.domain.ResponseResult;
import com.buka.dto.RoleDto;
import com.buka.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/system/role/list")
    public ResponseResult list(int pageNum, int pageSize, String roleName, @RequestParam(defaultValue = "-1") int status) {
        return roleService.list(pageNum, pageSize, roleName, status);
    }

    @PutMapping("/system/role/changeStatus")
    public ResponseResult changeStatus(@RequestBody RoleDto roleDto) {
        return roleService.changeStatus(roleDto);
    }

    @PostMapping("/system/role")
    public ResponseResult add(@RequestBody RoleDto roleDto) {
        return roleService.add(roleDto);
    }

    @GetMapping("/system/role/{id}")
    public ResponseResult getRoleById(@PathVariable("id") int id) {
        return roleService.getRoleById(id);
    }

    @PutMapping("/system/role")
    public ResponseResult updateRole(@RequestBody RoleDto roleDto) {
        return roleService.updateRole(roleDto);
    }

    @GetMapping("/system/role/listAllRole")
    public ResponseResult listAllRole() {
        return roleService.listAllRole();
    }

    @DeleteMapping("/system/role/{ids}")
    public ResponseResult deleteRoles(@PathVariable("ids") Long[] ids) {
        return roleService.deleteRoles(ids);
    }
}
